#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    void DeepSearch(TreeNode* node, vector<string>& ret, string str)
    {
        if (node == nullptr) return;
        str += to_string(node->val);
        if (node->left != nullptr || node->right != nullptr)
        {
            str += "->";
            DeepSearch(node->left, ret, str);
            DeepSearch(node->right, ret, str);
        }
        else
        {
            ret.push_back(str);
        }
        return;
    }
    vector<string> binaryTreePaths(TreeNode* root) {
        vector<string> ret;
        string s;
        DeepSearch(root, ret, s);
        return ret;
    }
};